﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Bussiness;
using Model;
using Data;

namespace hostal
{
    public partial class BuscarHabitacion : Form
    {
        DataTable temp = new DataTable();


        public BuscarHabitacion()
        {
            InitializeComponent();
        }

        private void callFormsChild(Form form)
        {
            form.MdiParent = this.MdiParent;
            form.Show();
            this.Close();
        }

        private void BuscarHabitacion_Load(object sender, EventArgs e)
        {
            DGHabitaciones.Columns.Clear();
            habitacionDataAccess hDal = new habitacionDataAccess();
            temp = hDal.buscarHabitaciones();
            DGHabitaciones.DataSource = temp;
            DGHabitaciones.Columns[0].Visible = false;
        }

        private void button17_Click(object sender, EventArgs e)
        {
            try
            {
                int fila = DGHabitaciones.CurrentRow.Index;
                if (fila != -1)
                {
                    ModificarHabitacion m = new ModificarHabitacion(DGHabitaciones.Rows[fila].Cells[1].Value.ToString());
                    callFormsChild(m);                  
                }
            }
            catch (SystemException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button19_Click(object sender, EventArgs e)
        {
            try
            {
                int fila = DGHabitaciones.CurrentRow.Index;
                if (fila != -1)
                {
                    string habitacion = DGHabitaciones.Rows[fila].Cells[0].Value.ToString();
                    DialogResult diag;
                    diag = MessageBox.Show("Seguro que decea deshabilitar la habitacion?", "Confirmacion", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                    if (diag == DialogResult.Yes)
                    {
                        manejadorHabitacion.DeshabilitarHabitacion(habitacion);
                        BuscarHabitacion m = new BuscarHabitacion();
                        callFormsChild(m);
                    }
                }
            }
            catch (SystemException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button16_Click(object sender, EventArgs e)
        {
            try
            {
                int fila = DGHabitaciones.CurrentRow.Index;
                if (fila != -1)
                {
                    DetalleHabitacion m = new DetalleHabitacion(DGHabitaciones.Rows[fila].Cells[1].Value.ToString());
                    m.ShowDialog();
                    //callFormsChild(m);
                }
            }
            catch (SystemException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DGHabitaciones.Columns.Clear();
            habitacionDataAccess hDal = new habitacionDataAccess();
            temp = hDal.buscarHabitacionesParams(tbBuscar.Text.ToLowerInvariant());
            DGHabitaciones.DataSource = temp;
        }
    }
}
